﻿<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta name="viewport" content="width=device-width" />
    <title>添加流程信息</title>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link href="../lib/layui/css/layui.min.css" rel="stylesheet" />
    <link href="../x-admin/css/font.css" rel="stylesheet" />
    <link href="../x-admin/css/xadmin.css" rel="stylesheet" />
    <script type="text/javascript" src="../lib/Base64/base64.min.js"></script>
    <script type="text/javascript" src="../linq.js/linq.js"></script>
    <script src="../lib/cookie/cookie.js"></script>
</head>
<body>
    <div class="layui-card-body" style="">
        <form name="newItem" id="newItem" lay-filter="newItem" class="layui-form">
            <input type="hidden" name="processCfgName" id="processCfgName" class="layui-input" />
            <input type="hidden" name="processType" id="processType" class="layui-input" />
            <input type="hidden" name="groupStepCode" id="groupStepCode" class="layui-input" />
            <div class="layui-form-item">
                <label class="layui-form-label">步骤序号:</label>
                <div class="layui-input-block">
                    <input type="text" name="number" id="number" lay-verify="title" autocomplete="off" required value="" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item" style="display:none">
                <label class="layui-form-label">执行类型:</label>
                <div class="layui-input-block">
                    <input type="text" name="executeType" lay-verify="title" autocomplete="off" value="file" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">选择模块:</label>
                <div class="layui-input-block">
                    <select name="moduleInfo" id="moduleInfo" lay-filter="moduleInfo" style="float:left;height:35px;margin-top:0px;margin-bottom:10px;width:80%;margin-left:10px;"></select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">选择文件:</label>
                <div class="layui-input-block">
                    <select name="fileName" id="fN" lay-search="" style="float:left;height:35px;margin-top:0px;margin-bottom:10px;width:80%;margin-left:10px;">
                        <option value="">请选择文件</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item" style="display:none">
                <label class="layui-form-label">步骤编码:</label>
                <div class="layui-input-block">
                    <input type="text" id="code" name="code" lay-verify="title" autocomplete="off" required placeholder="" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">备注信息:</label>
                <div class="layui-input-block">
                    <input type="text" id="zh_cn" name="zh_cn" lay-verify="title" autocomplete="off" required placeholder="" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="button" class="layui-btn" lay-submit lay-filter="save">立即提交</button>
                </div>
            </div>
        </form>
    </div>
    <script src="../lib/layui/layui.js"></script>
    <script type="text/javascript">
        function getrequest() {
            var url = location.search; //获取url中"?"符后的字串
            var theRequest = new Object();
            if (url.indexOf("?") != -1) {
                var str = url.substr(1);
                strs = str.split("&");
                for (var i = 0; i < strs.length; i++) {
                    theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
                }
            }
            return theRequest;
        }

        layui.use(['form','table'], function () {
            var $ = layui.$;
            var form = layui.form;
            var fileName = getrequest().fileName;
            var processType = getrequest().processType;
            $(function () {
                load();
            })
            form.render();
            form.on('submit(save)', function (data) {
                $.ajax({
                    type: "post",
                    url: localStorage.getItem('hosttingaddr') + "/Manager/ProcessCfgFile/udpitem",
                    headers: {
                        user: getCookie("userinfo"),
                        version: getCookie("version")
                    },
                    data: data.field,
                    success: function (data) {
                        if (data == "success") {
                            layer.msg('保存成功!', { icon: 1, time: 1000 });
                            var index = parent.layer.getFrameIndex(window.name); //获取当前窗口的name
                            parent.layer.close(index);
                        }
                    },
                    error: function (data) {
                        layer.msg('保存失败!', { icon: 1, time: 1000 });
                        var index = parent.layer.getFrameIndex(window.name); //获取当前窗口的name
                        parent.layer.close(index);
                    }
                });
            })

            form.on('select(moduleInfo)', function (el) {
                var obj = el.elem;
                var value = el.value;
                layui.jquery.ajax({
                    type: "get",
                    url: localStorage.getItem('hosttingaddr') + "/Manager/ProcessCfgFile/getfiles?parentDir=" + value,
                    success: function (result) {
                        $("#fN").empty();
                        var dirs = result.split(",");
                        var i;
                        var htmlStr = "<option value=\"\"></option>";
                        for (i = 0; i < dirs.length; i++) {
                            htmlStr += "<option value='" + dirs[i].split("-")[0] + "'>" + dirs[i].split("-")[1] + "</option>";

                        }
                        $("#fN").html(htmlStr);
                        form.render('select');
                        var defaultNote = $("#moduleInfo").find("option:selected").text();
                        $("#zh_cn").attr("value", defaultNote);
                    }
                });

            });

            function load() {
                layui.jquery.ajax({
                    url: localStorage.getItem('hosttingaddr') + "/Manager/ProcessCfgFile/additem",
                    method: "Get",
                    headers: {
                        user: getCookie("userinfo"),
                        version: getCookie("version")
                    },
                    data: {
                        fileName: fileName,
                        processType: processType
                    },
                    dataType: 'json',
                    success: function (res) {
                        form.val("newItem", {
                            "number": res.stepnum,
                            "processCfgName": fileName,
                            "groupStepCode": getrequest().groupStepCode,
                            "processType": processType
                        });
                        var htmlstr = "<option value=\"\"></option>";
                        res.data.forEach(function (o) {
                            htmlstr += "<option value=\"" + o.code + "\">" + o.name + "</option>";
                        });
                        $("#moduleInfo").html(htmlstr);
                        form.render();
                    }
                });
            }
        })
    </script>
</body>
</html>